package net.gzw1993.runmate.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by guoziwei on 2015/8/15.
 */
public abstract class SimpleBaseAdapter<T> extends BaseAdapter {

    protected List<T> mList = new ArrayList<>();
    protected Context mContext;
    protected LayoutInflater inflater;

    public SimpleBaseAdapter(Context context) {
        mContext = context;
        inflater = LayoutInflater.from(context);
    }

    public void addItems(List<T> list) {
        mList.addAll(list);
        notifyDataSetChanged();
    }

    public void replace(List<T> list) {
        mList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getItemView(position, convertView, parent);
    }

    public abstract View getItemView(int position, View convertView, ViewGroup parent);
}
